<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }

//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.
if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', staysmall, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(24);
	do_html_footer();
	exit;
	}

// Get our variables
if (!empty($_POST)) {
	$values['submit'] = $_POST['submit'];
	$values['badge_type'] = $_POST['badge_type'];
	$values['cost'] = floatval($_POST['cost']);
	$values['description'] = $_POST['description'];
	if (!empty($_POST['badge_type_id'])) {
		$values['badge_type_id'] = $_POST['badge_type_id'];
		}
	if (!empty($_POST['user_available'])) {
		$values['user_available'] = $_POST['user_available'];
		} else {
		$values['user_available'] = 'f';
		}
	}

if (isset($values['badge_type_id']) && isset($_POST['edit'])) {
	do_html_header('Manage Badges', staysmall, $uny);
	$badge_details = pg_fetch_array(get_badge_types($values['badge_type_id']));
	print_badge_entry_form($badge_details);
	print_badge_list();
	do_html_footer(news);
	exit;
	}

if (!empty($values) && isset($values)) {
	do_html_header('Manage Badges', staysmall, $uny);
	if (!isset($values['badge_type_id'])) {
		insert_badge_type($values);
		}
	if (isset($values['badge_type_id'])) {
		update_badge_type($values);
		}
	print_badge_entry_form();
	print_badge_list();
	do_html_footer(news);
	exit;
	}
	
if (empty($_POST)) {
	do_html_header('Manage Badges', staysmall, $uny);
	print_badge_entry_form();
	print_badge_list();
	do_html_footer(news);
	exit;
	}